package drawPropertyCommands;

import java.awt.BasicStroke;
import java.awt.Stroke;

/**
 * The stroke modifier will take an input stroke and modify the given graphicsProperties.
 * The list of get methods are given for the subclass to override so that it can modify
 * just one of the attributes.
 * 
 * @author KevinWang
 *
 */
public abstract class StrokeModifier implements IDrawModifier {
    private Stroke stroke;
    
    /**
     * This is the main execute method that will modify the GraphicsProperties by creating a
     * new Stroke object to put into the GraphicsProperties
     */
    @Override
    public void modify(GraphicsProperties graphicsProperties) {
        Stroke s = graphicsProperties.getStroke();
        Stroke newStroke = new BasicStroke(getWidth(s), getCap(s), getJoin(s), getMiterLimit(s), getDash(s), getDashPhase(s));
        graphicsProperties.setStroke(newStroke);
        
    }
    
    /**
     * return current Stroke's cap
     * @param s- Stroke
     * @return cap
     */
    protected int getCap(Stroke s){
        return ((BasicStroke)s).getEndCap();
    }
    
    /**
     * return current Stroke's Join
     * @param s- Stroke
     * @return Join
     */
    protected int getJoin(Stroke s){
        return ((BasicStroke)s).getLineJoin();
    }
    
    /**
     * return current Stroke's Width
     * @param s- Stroke
     * @return Width
     */
    protected float getWidth(Stroke s){
        return ((BasicStroke)s).getLineWidth();
    }
    
    /**
     * return current Stroke's Dash
     * @param s- Stroke
     * @return Dash
     */
    protected float[] getDash(Stroke s){
        return ((BasicStroke)s).getDashArray();
    }
    
    /**
     * return current Stroke's DashPhase
     * @param s- Stroke
     * @return DashPhase
     */
    protected float getDashPhase(Stroke s){
        return ((BasicStroke)s).getDashPhase();
    }
    
    /**
     * return current Stroke's MiterLimit
     * @param s- Stroke
     * @return MiterLimit
     */
    protected float getMiterLimit(Stroke s){
        return ((BasicStroke)s).getMiterLimit();
    }

}
